import re
import tkinter as tk
from tkinter import messagebox
win=tk.Tk()
win.title("My First GUI")
win.geometry("400x200+100+100")
win.resizable(0,0)
tk.Label(win,text="账号：").grid(row=0)
tk.Label(win,text="密码：").grid(row=1)
Dy_String1=tk.StringVar()
Dy_String2=tk.StringVar()
def login():
    messagebox.showinfo(title="提示！",message="猪妞欢迎你")
tk.Button(win,text="登录",width=10,command=login).grid(row=3,column=0,sticky=tk.W,padx=10,pady=5)
tk.Button(win,text="退出",width=10,command=win.quit).grid(row=3,column=1,sticky=tk.E,padx=10,pady=5)
def checkusername():
    username=e1.get()
    if not username.isdigit() :
        messagebox.showwarning(title="提示！",message="用户名必须为数字")
        return  False
    return True
def checkpassword():
    password=e2.get()
    if len(password)<8 :
        messagebox.showwarning(title="提示！",message="密码长度不够")
        return  False
    elif not re.search(r'[a-z]',password):
        messagebox.showwarning(title="提示！",message="密码格式错误，必须包含小写字母")
        return  False
    elif not re.search(r'[!@#$%^&*(),.?":{}|<>]',password):
        messagebox.showwarning(title="提示！",message="密码格式错误，必须包含特殊字符")
        return  False
    elif not re.search(r'[A-Z]',password):
        messagebox.showwarning(title="提示！",message="密码格式错误，必须包含大写字母")
        return  False
    elif not re.search(r'[0-9]',password):
        messagebox.showwarning(title="提示！",message="密码格式错误，必须包含数字")
        return  False
    return True
e1 = tk.Entry(win,textvariable=Dy_String1,validate="focusout",validatecommand=checkusername)
e2 = tk.Entry(win,show="*",textvariable=Dy_String2,validate="focusout",validatecommand=checkpassword)
e1.grid(row=0,column=1,padx=10,pady=5)
e2.grid(row=1,column=1,padx=10,pady=5)
win.mainloop()